using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Linq;
using Telerik.Web.UI;
  
public partial class Admin : BaseMasterPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        menu.DataBound += new EventHandler(menu_DataBound);
        if (!IsPostBack)
        {
            ReBindBreadCrumbs();

            if (!Request.IsAuthenticated)
            {
                /*btnLogout.Visible = false;
                btnDetails.Visible = false;*/
            }
            menu.DataBind();
        }
    }

    void menu_DataBound(object sender, EventArgs e)
    {
        if (Page.AcmsContext != null && Page.AcmsContext.SiteId > 0)
        {
            var customItems = Acms.Bll.CustomAdminPage.GetAllBySiteId(Page.AcmsContext.SiteId).ToList().OrderBy(x => x.Sequence);
            if (customItems != null && menu.Items.Count >= 4)
            {
                menu.Items[2].Items.AddRange(customItems.Where(x => x.Section == Acms.Bll.CustomAdminPage.Sections.Data).Select(x => new RadMenuItem(x.Name, string.Format("~/Custom/Default.aspx?Name={0}", Server.UrlEncode(x.Name)))));
                menu.Items[3].Items.AddRange(customItems.Where(x => x.Section == Acms.Bll.CustomAdminPage.Sections.Settings).Select(x => new RadMenuItem(x.Name, string.Format("~/Custom/Default.aspx?Name={0}", Server.UrlEncode(x.Name)))));
            }
        }
    }

    protected void btnLogout_Click(object sender, EventArgs e)
    {
        FormsAuthentication.SignOut();
        Response.Redirect("~");
    }


    public override void ReBindBreadCrumbs()
    {
        BaseMasterPage.BreadCrumbCollection tmpBreadcrumbs = new BaseMasterPage.BreadCrumbCollection();
        tmpBreadcrumbs.Add("Home", "~");
        Page.GetBreadCrumbs(tmpBreadcrumbs);
        breadcrumbs.DataSource = tmpBreadcrumbs.Select((item, index) => new { Name = item.Name, Url = (item.Url ?? "~/NoPage.aspx"), IsLast = index == tmpBreadcrumbs.Count - 1 });
        breadcrumbs.DataBind();
    }

}
